<?php include('src/listUser_cs.php');
@session_start();
$_SESSION['varMenu'] = 'Usuarios'; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="../js/jquery.js" type="text/javascript"></script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Lista Usuarios</title>
<link href="style.css" rel="stylesheet" type="text/css" />

<script type="text/javascript">
<!--
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>

</head>

<body class="style" onload="MM_preloadImages('images/menu2.png','images/menu3.png','images/menu.png','images/menu4.png','images/menu5.png','images/menu6.png','images/menu7.png','images/menu8.png','images/menu9.png','images/menu10.png','images/menu11.png')">

<div id="container">
  <?php include('header.php');?>
  <div id="mainContent">  
    <?php include('menuTop.php');?>
    <div id="bg">
		<form name="form1" id="form1" method="post" action="">
      <table width="100%" cellpadding="0" cellspacing="0">        
        <tr>
          <td colspan="5">
		  <table width="100%" bgcolor="#82241B">
              <tbody>
                <tr>
                  <td width="20%"> 
						<input type="button" name="agregar" id="agregar" 
						value="Agregar Usuario" onclick="location.href='add_user.php'"/> 
				  </td>
                  <td width="20%"> </td>
                  <td width="20%">
				  <input name="buscar" type="text" size="35"
					value="<?php if(isset($buscarValue)) echo $buscarValue?>" />
                  </td>
                  <td width="20%" align="center"><input type="submit" name="Submit" value="Search"/></td>
                </tr>
              </tbody>
          </table></td>
        </tr>
        <tr>
          <td colspan="2" align="left">
			<?php echo $totalArchivos;?> of 
			<a href="?inicio=<?php echo $inicio?>&cantidad=<?php echo $cantidad;?>"
			style="text-decoration:none; color:#FF0000"><?php echo '<B>'.$all.'</B>';?>
			</a>
			</td>
          <td colspan="3" align="right">
		  	<a href="?inicio=0&cantidad=25<?php echo $parametrosBuscador?>" style="text-decoration:none; color:#0000FF">25</a> |
			<a href="?inicio=0&cantidad=50<?php echo $parametrosBuscador?>" style="text-decoration:none; color:#0000FF">50</a> |
			<a href="?inicio=0&cantidad=100<?php echo $parametrosBuscador?>" style="text-decoration:none; color:#0000FF;">100</a> |
			<a href="?inicio=0&cantidad=<?php echo $all.$parametrosBuscador?>" style="text-decoration:none; color:#0000FF">All</a>
		  </td>
        </tr>
        <tr>
          <td colspan="5" align="center"> </td>
        </tr>
      </table>
      <h1>        Lista de Usuarios<br />
      </h1>
      <div id="list"><table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td colspan="8" align="center" valign="middle"><table width="100%" height="20px" border="0" align="left" cellpadding="0" cellspacing="0">
        <tr>
          <td width="1%" bgcolor="#000000">&nbsp;</td>
          <td width="22%" align="center" valign="middle" bgcolor="#000000"><h1><a href="list_user.php?inicio=<?php echo $inicio?>&cantidad=<?php echo $cantidad?><?php echo $parametrosBuscador?>&order_by=use_type" style="text-decoration:none; color:#FFFFFF">Tipo Usuario</a></h1></td>
          <td width="1%" background="images/item.png" bgcolor="#000000">&nbsp;</td>
          <td width="22%" align="center" valign="middle" bgcolor="#000000"><h1><a href="list_user.php?inicio=<?php echo $inicio?>&cantidad=<?php echo $cantidad?><?php echo $parametrosBuscador?>&order_by=use_name" style="text-decoration:none; color:#FFFFFF">Nombre</a></h1>            </td>
          <td width="1%" background="images/item.png" bgcolor="#000000">&nbsp;</td>
          <td width="22%" align="center" valign="middle" bgcolor="#000000"><h1><a href="list_user.php?inicio=<?php echo $inicio?>&cantidad=<?php echo $cantidad?><?php echo $parametrosBuscador?>&order_by=use_email" style="text-decoration:none; color:#FFFFFF">Email</a></h1>            </td>
          <td width="1%" background="images/item.png" bgcolor="#000000">&nbsp;</td>
          <td width="14%" align="center" valign="middle" bgcolor="#000000"><h1><a href="list_user.php?inicio=<?php echo $inicio?>&cantidad=<?php echo $cantidad?><?php echo $parametrosBuscador?>&order_by=use_login" style="text-decoration:none; color:#FFFFFF">Dependencia</a></h1></td>
		
          <td width="1%" background="images/item.png" bgcolor="#000000">&nbsp;</td>          
		  <td width="14%" align="center" valign="middle" bgcolor="#000000"><h1>Actions</h1></td>
		
          <td width="1%" bgcolor="#000000">&nbsp;</td>
        </tr>
      </table></td>
      </tr>
  </table>
  <?php 
		for($i=0;$i<count($list_users);$i++)
		{ 
		  $status = '';
		switch($list_users[$i]->status)
		{
		case 1: 
			$status = 'Active';
			$color_letra = '#008000';
			break;
		case 2: 
			$status = 'Inactive';
			$color_letra = '#FF6600';
			break;
		case 3: 
			$status = 'Blocked';
			$color_letra = '#0000CD';
			break;		
		case 4: 
			$status = 'eliminated';
			$color_letra = '#FF0000';
			break;		
		} 
	?>  
  <table width="100%" border="0" cellspacing="0" cellpadding="0" id="<?php echo 'tr'.$i;?>" >
    <tr>
      <td bgcolor="#FBFBFB">
		  <table width="100%" border="0" cellspacing="0" cellpadding="0">
			<tr>
				  <td width="1%">&nbsp;</td>
				  <td width="22%" align="center"><?php echo $list_users[$i]->type;?></td>
				  <td width="1%" background="images/item.png">&nbsp;</td>
				  <td width="22%" align="center"><?php echo $list_users[$i]->name;?></td>
				  <td width="1%" background="images/item.png">&nbsp;</td>
				  <td width="22%" align="center"><?php echo $list_users[$i]->email;?></td>
				  <td width="1%" background="images/item.png">&nbsp;</td>
				  <td width="14%" align="center"><?php echo $list_users[$i]->dependencia;?></td>
				  
				  <td width="1%" background="images/item.png">&nbsp;</td>
				  <td width="14%" align="center">
					  <table width="100%" border="0" cellpadding="2" cellspacing="0" class="iconosTabla">
						<tr>
						  <td align="center" valign="middle">						  
						  <a href="edit_user.php?code=<?php echo $list_users[$i]->code;?>" style="text-decoration:none;"
						  title="<?php echo $list_users[$i]->name;?> Editar Usuario">
						  <img src="images/editar.png" alt="Editar" width="15" height="17" border="0" /></a>
						  </td>
						  <td align="center" valign="middle">
						  <?php if($list_users[$i]->code != 1){?>
						  <a href="javascript:;" style="text-decoration:none;"
									 onclick="javascript: return userDelete(<?php echo $list_users[$i]->code;?>,<?php echo $i;?>);">
									<img src="images/eliminar_reg.png" alt="Eliminar" width="15" height="17" border="0" /></a>
						  <?php }?>
						  </td>
						  </tr>
					  </table>
				  </td>
				  
				  <td width="1%">&nbsp;</td>
			</tr>
		  </table>
	  </td>
    </tr>
  </table>
	  <?php }
		if($totalArchivos>$cantidad)
		{ 
		?>
		<table width="70%" border="0" align="center" bgcolor="#FFFFFF">
			<tr>
				<td align="left" width="33%">
					<a href="<?php echo $anterior;?>" class="texto_link"><strong>Preview</strong></a>
				</td>
				<td align="center" width="34%"><?php echo $paginas;?></td>
				<td align="right" width="33%">
					<a href="<?php echo $siguiente;?>" class="texto_link"><strong>Next</strong></a>
				</td>
			</tr>
		</table>
  		<?php }?>
  
  </td>
    </tr>
  <tr>
    <td bgcolor="#000000">&nbsp;</td>
    </tr>
</table>
</div>
      <br />
	  	</form>
    </div>
    <br />
    <br />
    <!-- end #mainContent -->
  </div>
  <?php include('footer.php');?>
  <!-- end #container --></div>

</body>
</html>
<script language="javascript" type="text/javascript">
 
function userDelete(code,id)
{
	if(confirm('Esta seguro de borrar este registro?') )
	{
	   jQuery.ajax({
			type: "POST",
			url: "deleteUser.php",
			data: 'code='+code,
			success: function(msg)
			{			
				if(msg==1)
				{	
					tr = document.getElementById("tr"+id);
					padre = tr.parentNode;
					padre.removeChild(tr);									
				}
				else
				{
					alert('El usuario no fue eliminado','Alert Dialog');	
				}			
			}
			});		
	}
	
	
}
 
</script>
